cmake_minimum_required(VERSION 3.16)

# 递归目录下的c文件
file(GLOB_RECURSE c_files ./*.c)

# 递归目录下的头文件
file(GLOB_RECURSE h_files ./*.h)

# 生成动态库和静态库
add_library(sub_lib_shared SHARED ${c_files})
add_library(sub_lib_static STATIC ${c_files})

# 设置库的名称
set_target_properties(sub_lib_shared PROPERTIES OUTPUT_NAME "sub")
set_target_properties(sub_lib_static PROPERTIES OUTPUT_NAME "sub")

# 设置库的版本
set_target_properties(sub_lib_shared PROPERTIES VERSION 1.0 SOVERSION 1)


# 安装库文件, 默认安装到 /usr/local/lib
INSTALL(TARGETS sub_lib_shared sub_lib_static
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib)

# 安装头文件, 默认安装到 /usr/local/include
INSTALL(FILES ${h_files} DESTINATION include)